package cn.edu;

import cn.edu.dao.UserDao;
import cn.edu.pojo.User;
import cn.edu.pojo.vo.UserVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@SpringBootTest
public class MybatisPlus02DMLApplication {
    @Autowired
    private UserDao userDao;

    @Test
    void testDeleteById(){
        userDao.deleteById(1L);
    }

    @Test
    void testFind(){
        System.out.println(userDao.selectList(null));
    }

    /**
     * 需求:根据传入的id集合将数据库表中的数据删除掉。
     */
    @Test
    void testDelete() {
        List<Long> list = new ArrayList<>();
        list.add(7L);
        list.add(8L);
        userDao.deleteBatchIds(list);
    }

    /**
     * 需求：根据传入的ID集合查询用户信息
     */
    @Test
    void testGetByIds() {
        List<Long> list = new ArrayList<>();
        list.add(1L);
        list.add(2L);
        list.add(3L);
        userDao.selectBatchIds(list);
    }

    @Test
    void testUpdate() {
        User user = new User();
        user.setId(2L);
        user.setName("Jim111");
        userDao.updateById(user);
    }

    @Test
    void testUpdate2() {
        User user = new User();
        user.setId(2L);
        user.setName("Jim222");
        user.setVersion(1);
        userDao.updateById(user);
    }

    @Test
    void testUpdate3() {
        User user = userDao.selectById(2L);
        user.setName("Jim333");
        userDao.updateById(user);
    }

    @Test
    void testUpdate4() {
        User user = userDao.selectById(2L);
        User user2 = userDao.selectById(2L);
        user2.setName("Jim444");
        userDao.updateById(user2);
        user.setName("Jim555");
        userDao.updateById(user);
    }

}
